package sandbox;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created by Sergii on 3/18/14.
 */
public class BrowseThreeSitesAndCheckSomething {

    private WebDriver driver;

    @BeforeTest
    public void setUp(){
        //FirefoxProfile profile = new FirefoxProfile();
        //profile.setEnableNativeEvents(true);
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }


    @Test
    public void checkThirdSiteWithAssert() {
        driver.get("http://hotline.ua/brands/samsung/");
        WebElement samsungLink = driver.findElement(By.xpath("//*[@id=\"test\"]/div[2]/div[2]/span[1]/a"));
        samsungLink.click();
        for(String winHandle : driver.getWindowHandles()){
            driver.switchTo().window(winHandle);
        }
        driver.findElement(By.xpath(".//*[@id='banner']/div[1]/a/div")).click();

        Assert.assertEquals(driver.getCurrentUrl(), "http://samsungshop.com.ua/",
                "Internet shop page was not reached!");
    }
    @AfterTest
    public void tearDown(){
        driver.quit();
    }
}
